package d4_map;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;

public class t2 {
    public static void main(String[] args) {
        Map<String, Double> map = new HashMap<>();
        map.put("A", 1.1);
        map.put("B", 2.2);
        map.put("C", 3.3);
        map.put("D", 4.4);
        map.put("E", 5.5);

        Set<String> keys = map.keySet();//把键放集合里
        for (String key : keys) {//方法1
            System.out.println(key+"="+map.get(key));
        }
        System.out.println("--------------------------------------------------------------------------------");

        //方法2
        Set<Map.Entry<String, Double>> et = map.entrySet(); //entry方法提供类型
        for (Map.Entry<String, Double> e : et) {
            System.out.println(e.getKey()+"="+e.getValue());
        }

        //方法3 lambda表达式
        map.forEach((k,v)->{
            System.out.println(k+v);
        });

        map.forEach(new BiConsumer<String, Double>() {
            @Override
            public void accept(String k, Double v) {
                System.out.println(k+"="+v);
            }
        });

    }
}
